﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZX.OA.Model;

namespace ZX.OA.DAL
{
    /// <summary>
    /// 请假信息的操作
    /// </summary>
    public class LeaveDal
    {
        /// <summary>
        /// EF的链接
        /// </summary>
        Entity entity = new Entity();
        /// <summary>
        /// 请假列表的显示
        /// </summary>
        /// <returns></returns>
        public List<LeaveInfo> Show_LeaveInfo()
        {
            return entity.LeaveInfo.ToList();
        }
        /// <summary>
        /// 部门下拉框显示
        /// </summary>
        /// <returns></returns>
        public List<DeptInfo> Drop_DeptInfo()
        {
            return entity.DeptInfo.ToList();
        }
        /// <summary>
        /// 添加请假信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Add_LeaveInfo(LeaveInfo leave)
        {
            entity.LeaveInfo.Add(leave);
            return entity.SaveChanges();
        }
        /// <summary>
        /// 显示请假详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public LeaveInfo Upd_LeaveInfo(int id)
        {
            return entity.LeaveInfo.Find(id);
        }
        /// <summary>
        /// 撤销请假信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Del_LeaveInfo(int id)
        {
            entity.LeaveInfo.Remove(entity.LeaveInfo.Find(id));
            return entity.SaveChanges();

        }
        /// <summary>
        /// 多条件查询请假信息
        /// </summary>
        /// <param name="EvectionPerson">请假人</param>
        /// <param name="DeptId">部门</param>
        /// <returns></returns>
        public List<LeaveInfo> Sel_EvectionInfo(string LeavePerson, int? DeptId)
        {
            return entity.LeaveInfo.Where((p => (string.IsNullOrEmpty(LeavePerson) ? true : p.LeavePerson.Contains(LeavePerson)) || (p.DeptId == null ? true : p.DeptId == DeptId))).ToList();
        }

    }
}
